package com.cmcc.linlaker.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.http.ConfigManager;
import com.cmcc.linlaker.ui.upload.CheckPlanActivity;
import com.cmcc.linlaker.ui.upload.CheckZxActivity;
import com.cmcc.linlaker.ui.upload.CheckingTaskActivity;
import com.cmcc.linlaker.ui.upload.FinishTaskActivity;
import com.cmcc.linlaker.ui.upload.SelfDealActivity;
import com.cmcc.linlaker.ui.upload.UploadHistoryActivity;
import com.cmcc.linlaker.ui.upload.UploadHistoryActivity2;

public class UploadFragment extends Fragment implements View.OnClickListener {

    private View fragmentView;

    public UploadFragment() {

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        fragmentView = inflater.inflate(R.layout.fragment_upload, container, false);

        initView();

        return fragmentView;

    }

    private TextView text_task_num, text_zx_num;
    private LinearLayout layout_upload_plan, layout_upload_history, layout_upload_task, layout_upload_setting, layout_upload_zx, layout_self_deal;

    private void initView() {
        text_task_num = fragmentView.findViewById(R.id.text_task_num);
        text_zx_num = fragmentView.findViewById(R.id.text_zx_num);

        layout_upload_history = fragmentView.findViewById(R.id.layout_upload_history);
        layout_upload_history.setOnClickListener(this);
        layout_upload_task = fragmentView.findViewById(R.id.layout_upload_task);
        layout_upload_task.setOnClickListener(this);
        layout_upload_setting = fragmentView.findViewById(R.id.layout_upload_setting);
        layout_upload_setting.setOnClickListener(this);
        layout_upload_plan = fragmentView.findViewById(R.id.layout_upload_plan);
        layout_upload_plan.setOnClickListener(this);
        layout_upload_zx = fragmentView.findViewById(R.id.layout_upload_zx);
        layout_upload_zx.setOnClickListener(this);
        layout_self_deal = fragmentView.findViewById(R.id.layout_self_deal);
        layout_self_deal.setOnClickListener(this);

        if (ConfigManager.loginData != null) {
            if (ConfigManager.loginData.taskCount != null) {
                if (!TextUtils.isEmpty(ConfigManager.loginData.taskCount.patrolTaskTotal)) {
                    if (!ConfigManager.loginData.taskCount.patrolTaskTotal.equals("0")) {
                        text_task_num.setVisibility(View.VISIBLE);
                        text_task_num.setText(ConfigManager.loginData.taskCount.patrolTaskTotal);
                    } else {
                        text_task_num.setVisibility(View.GONE);
                    }
                } else {
                    text_task_num.setVisibility(View.GONE);
                }
            } else {
                text_task_num.setVisibility(View.GONE);
            }

            if (ConfigManager.loginData.specialProblemCount != null) {
                if (!TextUtils.isEmpty(ConfigManager.loginData.specialProblemCount.messageTotal)) {
                    if (!ConfigManager.loginData.specialProblemCount.messageTotal.equals("0")) {
                        text_zx_num.setVisibility(View.VISIBLE);
                        text_zx_num.setText(ConfigManager.loginData.specialProblemCount.messageTotal);
                    } else {
                        text_zx_num.setVisibility(View.GONE);
                    }
                } else {
                    text_zx_num.setVisibility(View.GONE);
                }
            } else {
                text_zx_num.setVisibility(View.GONE);
            }

        } else {
            text_task_num.setVisibility(View.GONE);
            text_zx_num.setVisibility(View.GONE);
        }

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_upload_history:
                historyUpload();
                break;
            case R.id.layout_upload_task:
                uploadTask();
                break;
            case R.id.layout_upload_setting:
                uploadSetting();
                break;
            case R.id.layout_upload_plan:
                uploadPlan();
                break;
            case R.id.layout_upload_zx:
                uploadZx();
                break;
            case R.id.layout_self_deal:
                selfDeal();
                break;

        }
    }

    private void selfDeal() {
        Intent intent = new Intent(getActivity(), SelfDealActivity.class);
        startActivity(intent);
    }

    /**
     * 专项巡查
     */
    private void uploadZx() {
        Intent intent = new Intent(getActivity(), CheckZxActivity.class);
        startActivity(intent);
        text_zx_num.setVisibility(View.GONE);
    }

    /**
     * 巡查计划
     */
    private void uploadPlan() {
        Intent intent = new Intent(getActivity(), CheckPlanActivity.class);
        startActivity(intent);
    }

    /**
     * 问题历史上报
     */
    private void historyUpload() {
        Intent intent = new Intent(getActivity(), UploadHistoryActivity2.class);
        startActivity(intent);
    }


    /**
     * 巡查任务
     */
    private void uploadTask() {
        Intent intent = new Intent(getActivity(), CheckingTaskActivity.class);
        startActivity(intent);
        text_task_num.setVisibility(View.GONE);
    }

    /**
     * 已处置任务
     */
    private void uploadSetting() {
        Intent intent = new Intent(getActivity(), FinishTaskActivity.class);
        startActivity(intent);
    }
}
